<?
class accountAction extends Action {
	public function index(){
		R('run/_initialize');
	}
	
	public function login(){
		$this->display();
	}
	
	public function loginz() {
		
		$id = $_REQUEST ['id'];
		if ($id == '') {
			$this->error ( '请输入用户名' );
		}
		
		$password = $_REQUEST ['password'];
		if ($password == '') {
			$this->error ( '请输入密码' );
		}
		
		$o = M ( 'user' );
		
		$where = "uid = '$id'";
		$where .= " OR uname = '$id'";
		$where .= " OR email = '$id'";
		$o->where ( $where );
		
		$r = $o->find ();
		
		if ($r ['uid'] != $id
		&& $r ['uname'] != $id
		&& $r ['email'] != $id) {
			$this->error ( '没有这个用户' );
		}
		
		if ($r ['password'] != $password) {
			$this->error ( '密码错误' );
		}
		
		if (strpos ( $r ['groups'], 'admin' ) === false) {
			$this->error ( '您不是管理员' );
		}
		
		//配色
//		$s = M ( 'user_sort' );
//		$color = $s->where ( "title = '{$r ['s1']}'" )->find ();
		
		//CK
		CK ( 'ac[id]',		$r ['id'] );
		CK ( 'ac[s1]',		$r ['id'] );
		//CK ( 'ac[uid]',	$r ['uid'] );
		CK ( 'ac[uname]',	base64_encode ( $r ['uname'] ) );
		//CK ( 'ac[email]',	$r ['email'] );
		CK ( 'ac[okey]',	$r ['okey'] );
		//CK ( 'ac[groups]',	$r ['groups'] );
		CK ( 'ac[color]',	$color ['color'] );
		CK ( 'ac[s1]', $r ['s1'] );

		
		//返回
		$backto = $_POST ['backto'];
		
		if ($backto == null
		|| strpos ( $backto, 'account/login' ) !== false
		|| strpos ( $backto, '_top' ) !== false) {
			$backto = "/adminiii.php";
		}
		
		header ( 'location:' . $backto );
	}
	
	public function logout() {
		
		$time = time();
		CK ( 'ac[id]',		'',	$time );
		CK ( 'ac[s1]',		'',	$time );
		CK ( 'ac[uname]',	'',	$time );
		CK ( 'ac[okey]',	'',	$time );
		CK ( 'ac[color]',	'',	$time );
		
		header ( "location:" . $_SERVER ['HTTP_REFERER'] );
	}

}
?>